﻿#include "TurnTableDecode_TurnTable_RunningState.h"

#include "TurnTableCodec.h"
#include "RegisterCenter_Device.h"
#include "Device.h"

TurnTableDecode_TurnTable_RunningState::TurnTableDecode_TurnTable_RunningState(TurnTableCodec *turnTableCodec)
{
  setObjectName(getClassNameFirstLow<TurnTableDecode_TurnTable_RunningState>());
  this->turnTableCodec=turnTableCodec;
}

TurnTableDecode_TurnTable_RunningState::~TurnTableDecode_TurnTable_RunningState()
{

}

void TurnTableDecode_TurnTable_RunningState::decode(char* const data,uint deviceId)
{
  uchar state=dataBodyToInt(data,1)&0xff;
  registerCenter_Device->getDeviceById(deviceId)->setTurnTable_runningState(state);
//  logSaver->saveLog(QStringLiteral("TurnTableCodec,turnTable running state:%1").arg(QString::number(state,16)),LogSaver::Debug);
//  if (state & 0x01) {
//      emit turnTableCodec->signal_turnTableTargetPositionState(TurnTableCodec::State_Reached,deviceId);
//    }
//  else {
//      emit turnTableCodec->signal_turnTableTargetPositionState(TurnTableCodec::State_NotReached,deviceId);
//    }
//  if (state & 0x02) {
//      emit turnTableCodec->signal_turnTableTargetRateState(TurnTableCodec::State_Reached,deviceId);
//    }
//  else {
//      emit turnTableCodec->signal_turnTableTargetRateState(TurnTableCodec::State_NotReached,deviceId);
//    }
//  if (state & 0x04) {
//      emit turnTableCodec->signal_turnTableTargetStop(TurnTableCodec::State_Reached,deviceId);
//    }
//  else {
//      emit turnTableCodec->signal_turnTableTargetStop(TurnTableCodec::State_NotReached,deviceId);
//    }
//  if (state & 0x08) {
//      emit turnTableCodec->signal_turnTablePowerState(TurnTableCodec::State_PowerOn,deviceId);
//    }
//  else {
//      emit turnTableCodec->signal_turnTablePowerState(TurnTableCodec::State_PowerOff,deviceId);
//    }
//  if (state & 0x10) {
//      emit turnTableCodec->signal_turnTableCircuitState(TurnTableCodec::State_CircuitClosed,deviceId);
//    }
//  else {
//      emit turnTableCodec->signal_turnTableCircuitState(TurnTableCodec::State_CircuitOpened,deviceId);
//    }
//  if (state & 0x20) {
//      emit turnTableCodec->signal_turnTableAmplifierState(TurnTableCodec::State_AmplifierBroken,deviceId);
//    }
//  else {
//      emit turnTableCodec->signal_turnTableAmplifierState(TurnTableCodec::State_AmplifierNormal,deviceId);
//    }
//  if (state & 0x40) {
//      emit turnTableCodec->signal_turnTableRunningState(TurnTableCodec::State_TurnTableRunning,deviceId);
//    }
//  else {
//      emit turnTableCodec->signal_turnTableRunningState(TurnTableCodec::State_TurnTableStoped,deviceId);
//    }
}

RegisterCenter_Device* TurnTableDecode_TurnTable_RunningState::getRegisterCenter_Device()const
{
  return registerCenter_Device;
}

TurnTableDecode_TurnTable_RunningState* TurnTableDecode_TurnTable_RunningState::setRegisterCenter_Device(RegisterCenter_Device* const registerCenter_Device)
{
  this->registerCenter_Device=registerCenter_Device;
  printInjection(this,registerCenter_Device);
  return this;
}

void TurnTableDecode_TurnTable_RunningState::objectAutoInjection(QHash<QString,QObject*>* objMap)
{
  setRegisterCenter_Device(getObjFromMap<RegisterCenter_Device>(objMap));
}
